home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb8.arc
/
DIRSRCH.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-02-23
|
5KB
|
143 lines
{$v-}
program dirsrch;
{ This program will search a directory for a matching file name
and then print out it along with its size and attribute byte.
Other information is available in the record `dta_def'. Using
the same techniques, if the entry is a directory, it could be
saved and then searched recursively.
Jim Holtman
35 Dogwood Trail
Randolph, NJ 07869
(201) 361-3395
}
type
regset = record
ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
end;
fname = array[1..80] of char;
str80 = string[80];
dta_def = record
filler : array[1..21] of byte;
attribute : byte;
file_time : integer;
file_date : integer;
file_size : array[1..2] of integer;
file_name : fname;
end;
const
carry = 1;
directory = $10;
var
pattern : string[40];
procedure recurse;
var
dta : dta_def;
param : regset;
s_string : string[70];
r1,r2 : real;
dta_save : array[1..2] of integer;
current_directory : string[70];
{create a STRING out of the input characters}
function pack_name(var a1;
size : integer) : str80;
var
i : integer;
b : str80;
a : array[1..1000] of char absolute a1;
begin
i := 1;
b := '';
while (a[i]<>chr(0)) and (i <= size) do begin
b := b+a[i];
i := i+1;
end;
pack_name := b;
end;
begin
{ writeln('entering RECURSE');}
{DEBUG}
with param,dta do begin
ax := $2F00; {get DTA}
msdos(param);
dta_save[1] := es;
dta_save[2] := bx;
ax := $1A00; {set DTA}
ds := seg(dta);
dx := ofs(dta);
msdos(param);
ds := seg(pattern[1]);
dx := ofs(pattern[1]);
ax := $4E00; {find 1st}
cx := $FF;
msdos(param);
dx := 0; {get current directory -- default drive}
ds := seg(current_directory[1]);
si := ofs(current_directory[1]);
ax := $4700;
msdos(param);
current_directory := '\'+pack_name(current_directory[1],64);
while (flags and carry) = 0 do begin
s_string := pack_name(file_name,sizeof(file_name));
if ((attribute and directory) <> 0) and (s_string <> '.') and (
s_string <> '..') then begin
{writeln('decending to ',s_string);}
{DEBUG}
s_string := s_string+chr(0);
ax := $3B00; {CHDIR}
ds := seg(s_string[1]);
dx := ofs(s_string[1]);
msdos(param);
recurse; {recursive decent into next directory}
{writeln('going back');}
{DEBUG}
ax := $3B00; {go back}
s_string := '..'#0;
{go back to `parent'}
ds := seg(s_string[1]);
dx := ofs(s_string[1]);
msdos(param);
end
else begin
r1 := file_size[1];
r2 := file_size[2];
if r1 < 0 then r1 := r1+65536.0;
{take care of extension of}
if r2 < 0 then r2 := r2+65536.0;
{data into the sign bit}
s_string := current_directory+'\'+s_string;
writeln(s_string, '':(65-length(s_string)),(r2*65536.0+r1):7:
0, attribute:3);
end;
ax := $4F00; {get next}
msdos(param);
end;
ax := $1A00; {set DTA}
ds := dta_save[1];
dx := dta_save[2];
msdos(param);
end;
end;
begin
write('Pattern to search for - ');
readln(pattern);
pattern := pattern+chr(0);
recurse;
end.